package com.neusoft.tmall.ums.service.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.security.access.ConfigAttribute;
import org.springframework.security.access.SecurityConfig;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import com.neusoft.tmall.ums.entity.UmsResourceExample;
import com.neusoft.tmall.ums.entity.UmsResource;
import com.neusoft.tmall.ums.mapper.UmsResourceMapper;
import com.neusoft.tmall.ums.service.UmsResourceService;

@Service
public class UmsResourceServiceImpl extends ServiceImpl<UmsResourceMapper, UmsResource> implements UmsResourceService{

    @Override
    public long countByExample(UmsResourceExample example) {
        return baseMapper.countByExample(example);
    }
    @Override
    public int deleteByExample(UmsResourceExample example) {
        return baseMapper.deleteByExample(example);
    }
    @Override
    public List<UmsResource> selectByExample(UmsResourceExample example) {
        return baseMapper.selectByExample(example);
    }
    @Override
    public int updateByExampleSelective(UmsResource record,UmsResourceExample example) {
        return baseMapper.updateByExampleSelective(record,example);
    }
    @Override
    public int updateByExample(UmsResource record,UmsResourceExample example) {
        return baseMapper.updateByExample(record,example);
    }
    @Override
    public Map<String, ConfigAttribute> loadAuthResources() {
        //支持线程
        Map<String, ConfigAttribute> map = new ConcurrentHashMap<>();
        List<UmsResource> list = baseMapper.selectByExample(new UmsResourceExample());
        for (UmsResource item : list) {
            map.put(item.getUrl(), new SecurityConfig(item.getId() + ":" + item.getName()));
        }
        return map;
    }
}
